package 多线程.抢票;

public class buy extends Thread {
    String name;
    static int num=100;



    public buy(String name) {
    this.name=name;
    }

    @Override
    synchronized
    public void run() {
        synchronized (this){

        while (true) {
            Thread.currentThread().setName(name);


            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "买到" + num + "号票了");
            num--;

        }

    }
    }
}
